local _G = _G
local addon, ns = ...
local profile = ns.profile
local cfg = {}
local LabelUI
local noshow
if not _G.LabelUI_mod then
	_G.LabelUI_mod = {}	
end
local Auroramod = ns.Auroramod
  
local Easymailmod = CreateFrame("Frame", nil, UIParent)
  
local function Enablemod()
	if Auroramod.ready then
		if Auroramod.additions["EasymailFrames"] then
			Auroramod.additions["EasymailFrames"] = nil
		end
		--local texture = EasyMail_CheckAllButton:GetNormalTexture()
		--texture:SetTexCoord(0.1,0.45,0.1,0.45)
		Aurora[1].Reskin(EasyMail_CheckAllButton)
		--EasyMail_CheckAllButton:SetTexCoord(0.1,0.9,0.1,0.9)
		EasyMail_CheckAllButton:SetSize(25, 25)
		local checkalltex = EasyMail_CheckAllButton:CreateTexture(nil, "BACKGROUND")
		checkalltex:SetTexture("Interface\\AddOns\\LabelUI_AddOns\\\media\\CheckAllLU.tga")
		--checkalltex:SetSize(20, 20)
		checkalltex:SetTexCoord(0.085,0.465,0.085,0.465)
		checkalltex:SetPoint("TOPLEFT", EasyMail_CheckAllButton, "TOPLEFT", 2.5 ,-1.5)
		checkalltex:SetPoint("BOTTOMRIGHT", EasyMail_CheckAllButton, "BOTTOMRIGHT", -2.5 ,3.5)
		local checkallcheck = CreateFrame("CheckButton", nil, EasyMail_CheckAllButton, "ChatConfigCheckButtonTemplate")
		checkallcheck:EnableMouse(false)
		checkallcheck:SetChecked(true)
		checkallcheck:SetScale(0.85)
		Aurora[1].ReskinCheck(checkallcheck)
		checkallcheck:SetPoint("TOPLEFT", checkalltex, "TOPLEFT", 3 ,-3)
		EasyMail_CheckAllButton:SetScript("OnMouseDown", function ()
			if EasyMail_CheckAllButton:IsEnabled() then
				checkalltex:SetPoint("TOPLEFT", EasyMail_CheckAllButton, "TOPLEFT", 4 ,-3)
				checkalltex:SetPoint("BOTTOMRIGHT", EasyMail_CheckAllButton, "BOTTOMRIGHT", -1 ,2)	
			end	
		end)
		EasyMail_CheckAllButton:SetScript("OnMouseUp", function ()
			checkalltex:SetPoint("TOPLEFT", EasyMail_CheckAllButton, "TOPLEFT", 2.5 ,-1.5)
			checkalltex:SetPoint("BOTTOMRIGHT", EasyMail_CheckAllButton, "BOTTOMRIGHT", -2.5 ,3.5)	
		end)
		
		
		Aurora[1].Reskin(EasyMail_ClearAllButton)
		EasyMail_ClearAllButton:SetSize(25, 25)
		local clearalltex = EasyMail_ClearAllButton:CreateTexture(nil, "BACKGROUND")
		clearalltex:SetTexture("Interface\\AddOns\\LabelUI_AddOns\\\media\\CheckAllLU.tga")
		clearalltex:SetTexCoord(0.085,0.465,0.085,0.465)
		clearalltex:SetPoint("TOPLEFT", EasyMail_ClearAllButton, "TOPLEFT", 2.5 ,-1.5)
		clearalltex:SetPoint("BOTTOMRIGHT", EasyMail_ClearAllButton, "BOTTOMRIGHT", -2.5 ,3.5)
		EasyMail_ClearAllButton:SetPoint("TOPLEFT", EasyMail_CheckAllButton, "TOPRIGHT", 2 ,0)
		local clearallcheck = CreateFrame("CheckButton", nil, EasyMail_ClearAllButton, "ChatConfigCheckButtonTemplate")
		clearallcheck:EnableMouse(false)
		clearallcheck:SetChecked(false)
		clearallcheck:SetScale(0.85)
		Aurora[1].ReskinCheck(clearallcheck)
		clearallcheck:SetPoint("TOPLEFT", clearalltex, "TOPLEFT", 3 ,-3)
		EasyMail_ClearAllButton:SetScript("OnMouseDown", function ()
			if EasyMail_ClearAllButton:IsEnabled() then
				clearalltex:SetPoint("TOPLEFT", EasyMail_ClearAllButton, "TOPLEFT", 4 ,-3)
				clearalltex:SetPoint("BOTTOMRIGHT", EasyMail_ClearAllButton, "BOTTOMRIGHT", -1 ,2)	
			end	
		end)
		EasyMail_ClearAllButton:SetScript("OnMouseUp", function ()
			clearalltex:SetPoint("TOPLEFT", EasyMail_ClearAllButton, "TOPLEFT", 2.5 ,-1.5)
			clearalltex:SetPoint("BOTTOMRIGHT", EasyMail_ClearAllButton, "BOTTOMRIGHT", -2.5 ,3.5)	
		end)
		
		
		Aurora[1].Reskin(EasyMail_CheckPageButton)
		EasyMail_CheckPageButton:SetSize(25, 25)
		local checkpagetex = EasyMail_CheckPageButton:CreateTexture(nil, "ARTWORK")
		checkpagetex:SetTexture("Interface\\AddOns\\LabelUI_AddOns\\\media\\CheckPageLU.tga")
		checkpagetex:SetTexCoord(0.085,0.465,0.085,0.465)
		checkpagetex:SetPoint("TOPLEFT", EasyMail_CheckPageButton, "TOPLEFT", 2.5 ,-1.5)
		checkpagetex:SetPoint("BOTTOMRIGHT", EasyMail_CheckPageButton, "BOTTOMRIGHT", -2.5 ,3.5)
		EasyMail_CheckPageButton:SetPoint("TOPLEFT", EasyMail_ClearAllButton, "TOPRIGHT", 9 ,0)
		local checkpagecheck = CreateFrame("CheckButton", nil, EasyMail_CheckPageButton, "ChatConfigCheckButtonTemplate")
		checkpagecheck:EnableMouse(false)
		checkpagecheck:SetChecked(true)
		checkpagecheck:SetScale(0.85)
		Aurora[1].ReskinCheck(checkpagecheck)
		checkpagecheck:SetPoint("TOPLEFT", checkpagetex, "TOPLEFT", 3 ,-3)
		EasyMail_CheckPageButton:SetScript("OnMouseDown", function ()
			if EasyMail_CheckPageButton:IsEnabled() then
				checkpagetex:SetPoint("TOPLEFT", EasyMail_CheckPageButton, "TOPLEFT", 4 ,-3)
				checkpagetex:SetPoint("BOTTOMRIGHT", EasyMail_CheckPageButton, "BOTTOMRIGHT", -1 ,2)
			end		
		end)
		EasyMail_CheckPageButton:SetScript("OnMouseUp", function ()
			checkpagetex:SetPoint("TOPLEFT", EasyMail_CheckPageButton, "TOPLEFT", 2.5 ,-1.5)
			checkpagetex:SetPoint("BOTTOMRIGHT", EasyMail_CheckPageButton, "BOTTOMRIGHT", -2.5 ,3.5)	
		end)
		
		
		Aurora[1].Reskin(EasyMail_ClearPageButton)
		EasyMail_ClearPageButton:SetSize(25, 25)
		local clearpagetex = EasyMail_ClearPageButton:CreateTexture(nil, "ARTWORK")
		clearpagetex:SetTexture("Interface\\AddOns\\LabelUI_AddOns\\\media\\CheckPageLU.tga")
		clearpagetex:SetTexCoord(0.085,0.465,0.085,0.465)
		clearpagetex:SetPoint("TOPLEFT", EasyMail_ClearPageButton, "TOPLEFT", 2.5 ,-1.5)
		clearpagetex:SetPoint("BOTTOMRIGHT", EasyMail_ClearPageButton, "BOTTOMRIGHT", -2.5 ,3.5)
		EasyMail_ClearPageButton:SetPoint("TOPLEFT", EasyMail_CheckPageButton, "TOPRIGHT", 2 ,0)
		local clearpagecheck = CreateFrame("CheckButton", nil, EasyMail_ClearPageButton, "ChatConfigCheckButtonTemplate")
		clearpagecheck:EnableMouse(false)
		clearpagecheck:SetChecked(false)
		clearpagecheck:SetScale(0.85)
		Aurora[1].ReskinCheck(clearpagecheck)
		clearpagecheck:SetPoint("TOPLEFT", clearpagetex, "TOPLEFT", 3 ,-3)
		EasyMail_ClearPageButton:SetScript("OnMouseDown", function ()
			if EasyMail_ClearPageButton:IsEnabled() then
				clearpagetex:SetPoint("TOPLEFT", EasyMail_ClearPageButton, "TOPLEFT", 4 ,-3)
				clearpagetex:SetPoint("BOTTOMRIGHT", EasyMail_ClearPageButton, "BOTTOMRIGHT", -1 ,2)
			end	
		end)
		EasyMail_ClearPageButton:SetScript("OnMouseUp", function ()
			clearpagetex:SetPoint("TOPLEFT", EasyMail_ClearPageButton, "TOPLEFT", 2.5 ,-1.5)
			clearpagetex:SetPoint("BOTTOMRIGHT", EasyMail_ClearPageButton, "BOTTOMRIGHT", -2.5 ,3.5)	
		end)
		
		
		Aurora[1].Reskin(EasyMail_GetAllButton)
		EasyMail_GetAllButton:SetSize(82, 25)
		local getalltex = EasyMail_GetAllButton:CreateTexture(nil, "ARTWORK")
		getalltex:SetTexture("Interface\\AddOns\\LabelUI_AddOns\\\media\\GetCheckedLU.tga")
		getalltex:SetTexCoord(0.085,0.87,0.085,0.465)
		getalltex:SetPoint("TOPLEFT", EasyMail_GetAllButton, "TOPLEFT", 2.5 ,-1.5)
		getalltex:SetPoint("BOTTOMRIGHT", EasyMail_GetAllButton, "BOTTOMRIGHT", -2.5 ,3.5)
		EasyMail_GetAllButton:SetPoint("TOPLEFT", EasyMail_ClearPageButton, "TOPRIGHT", 9 ,0)
		local getallcheck = CreateFrame("CheckButton", nil, EasyMail_GetAllButton, "ChatConfigCheckButtonTemplate")
		getallcheck:EnableMouse(false)
		getallcheck:SetChecked(true)
		getallcheck:SetScale(0.85)
		Aurora[1].ReskinCheck(getallcheck)
		getallcheck:SetPoint("TOPLEFT", getalltex, "TOPLEFT", 3 ,-3)
		EasyMail_GetAllButton:SetScript("OnMouseDown", function ()
			if EasyMail_GetAllButton:IsEnabled() then
				getalltex:SetPoint("TOPLEFT", EasyMail_GetAllButton, "TOPLEFT", 4 ,-3)
				getalltex:SetPoint("BOTTOMRIGHT", EasyMail_GetAllButton, "BOTTOMRIGHT", -1 ,2)	
			end	
		end)
		EasyMail_GetAllButton:SetScript("OnMouseUp", function ()
			getalltex:SetPoint("TOPLEFT", EasyMail_GetAllButton, "TOPLEFT", 2.5 ,-1.5)
			getalltex:SetPoint("BOTTOMRIGHT", EasyMail_GetAllButton, "BOTTOMRIGHT", -2.5 ,3.5)	
		end)
		
		
		Aurora[1].Reskin(EasyMail_ForwardButton)
		Aurora[1].Reskin(EasyMail_AttButton)
		
		Aurora[1].Reskin(EasyMail_MailButton)
		EasyMail_MailButton:SetSize(25, 25)
		EasyMail_MailButton:SetPoint("TOPLEFT", EasyMail_MailButton:GetParent(), "TOPRIGHT", -1 ,0)
		local downtex = EasyMail_MailButton:CreateTexture(nil, "ARTWORK")
		downtex:SetTexture("Interface\\AddOns\\Aurora\\media\\arrow-down-active")
		downtex:SetSize(8, 8)
		downtex:SetPoint("CENTER")
		downtex:SetVertexColor(1, 1, 1)
		EasyMail_MailDropdownBackdrop:Hide()	
		Aurora[1].CreateBD(EasyMail_MailDropdown)
		
		for t = 1, INBOXITEMS_TO_DISPLAY do
			local frame = _G["EasyMail_CheckButton"..t] 
			Aurora[1].ReskinCheck(frame)
		end
		
	else
		Auroramod.additions["EasymailFrames"] = Enablemod	
	end	
end 
  
local function Init()
	_, _, _, enabled, _, reason = GetAddOnInfo("EasyMail")
	if reason == "MISSING" or not enabled then return end
	if Auroramod then
		Enablemod()
	end
end

function Easymailmod.InitMod(main, profilename)
	noshow = main.noshow 
	LabelUI = main
	main:AddInit(Init, "Addon EasyMailMod")
end 
  
_G.LabelUI_mod["Easymailmod"] = Easymailmod